# import socket
# cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)      #创建实例
# cli.connect(('localhost', 9000))                             #绑定ip端口
# data = cli.recv(1024)                      #收信息
# print(data.decode())                       #输出收到的信号
# cli.send('客户端发了'.encode())              #给目标发信息
# cli.close()                                #实例关闭


# import socket
# cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# cli.connect(('localhost', 9000))
#
# while 1:
#     msg = input('input>>>>').strip()
#     if not msg:
#         continue
#     if msg == 'q':
#         break
#     cli.send(msg.encode())
#     server = cli.recv(1024)
#     print('from server:', server.decode())




# import socket
# cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# cli.connect(('localhost', 9000))
# while 1:
#     cmd = input('input>>>>').strip()
#     if not cmd:
#         continue
#     if cmd == 'q':
#         break
#     #发送指令到服务器
#     cli.send(cmd.encode('utf-8'))
#     #接受命令的执行结果
#     data_size = int(cli.recv(1024).decode())    #接收到服务器端发送的数据大小
#     print(f'文件长度：{data_size}')
#     #cli.send(b'ok')    #为了防止粘包
#     #接收实际数据
#     res_size = 0
#     res = b''
#     while res_size < data_size:          #对收到的数据进行比较 一样大小了就是收到完整数据
#         data = cli.recv(1024)
#         res += data                      #把每次传入的数据加入res
#         res_size += len(data)
#     print(res.decode())
# cli.close()




#解决粘包的客户端
# import socket
# cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# cli.connect(('localhost', 9000))
# while 1:
#     cmd = input('input>>>>').strip()
#     if not cmd:
#         continue
#     if cmd == 'q':
#         break
#     #发送指令到服务器
#     cli.send(cmd.encode('utf-8'))
#     #接受命令的执行结果
#     raw_data_size = cli.recv(16).decode()     #接收到服务器端发送的固定命令长度消息头
#     data_size = int(raw_data_size.split('|')[0])
#     print(f'文件长度：{data_size}')
#
#     #接收实际数据
#     res_size = 0
#     res = b''
#     while res_size < data_size:          #对收到的数据进行比较 一样大小了就是收到完整数据
#         data = cli.recv(1024)
#         res += data                      #把每次传入的数据加入res
#         res_size += len(data)
#     print(res.decode())
# cli.close()













